﻿@namespace Blazorise.Docs.Docs.Examples

<TreeView Nodes="Items"
          GetChildNodes="@(item => item.Children)"
          HasChildNodes="@(item => item.Children?.Any() == true)"
          @bind-SelectedNode="selectedNode"
          @bind-ExpandedNodes="expandedNodes"
          Virtualize>
    <NodeContent>
        <Icon Name="IconName.Folder" />
        @context.Text
    </NodeContent>
</TreeView>

@code {
    public class Item
    {
        public string Text { get; set; }
        public IEnumerable<Item> Children { get; set; }
    }

    protected override void OnInitialized()
    {
        Items = Enumerable.Range( 1, 4 ).Select( rootIndex => new Item
        {
            Text = $"Root Node {rootIndex}",
            Children = Enumerable.Range( 1, 100 ).Select( childIndex => new Item
            {
                Text = $"Root {rootIndex} - Child {childIndex}",
                Children = Enumerable.Empty<Item>() // No children for the child nodes in this example
            } )
        } ).ToList();

        base.OnInitialized();
    }

    IEnumerable<Item> Items;

    IList<Item> expandedNodes = new List<Item>();
    Item selectedNode;
}